package com.example.zhangxin.myhuatuob2b.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.zhangxin.myhuatuob2b.R;
import com.example.zhangxin.myhuatuob2b.bean.GoodsList;

import org.xutils.x;

import java.util.ArrayList;

import static com.example.zhangxin.myhuatuob2b.R.id.textEvaluationCount;
import static com.example.zhangxin.myhuatuob2b.R.id.textGoodsName;
import static com.example.zhangxin.myhuatuob2b.R.id.textGoodsPrice;
import static com.example.zhangxin.myhuatuob2b.R.id.textGoodsType;
import static com.example.zhangxin.myhuatuob2b.R.id.textZengPin;

/**
 * Created by ZhangXin on 2016/10/13.
 */

public class GoodsListViewAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<GoodsList> data;

    public GoodsListViewAdapter(Context context, ArrayList<GoodsList> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context,R.layout.listivew_goods_item, null);
            holder.textGoodsName = (TextView) convertView.findViewById(textGoodsName);
            holder.textGoodsPrice = (TextView) convertView.findViewById(textGoodsPrice);
            holder.textEvaluationCount = (TextView) convertView.findViewById(textEvaluationCount);
            holder.textGoodsType = (TextView) convertView.findViewById(textGoodsType);
            holder.textZengPin = (TextView) convertView.findViewById(textZengPin);
            holder.imageGoodsPic = (ImageView) convertView.findViewById(R.id.imageGoodsPic);
            convertView.setTag(holder);

        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        GoodsList goodsList = data.get(position);
        holder.textGoodsName.setText(goodsList.getGoods_name());
        holder.textGoodsPrice.setText("￥"+goodsList.getGoods_price());
        holder.textEvaluationCount.setText("          ("+goodsList.getEvaluation_count()+"人)");
        x.image().bind(holder.imageGoodsPic,goodsList.getGoods_image_url());
        return convertView;
    }
    class ViewHolder {
        ImageView imageGoodsPic;
        TextView textGoodsName;
        TextView textGoodsPrice;
        LinearLayout imageXingJi;
        TextView textEvaluationCount;
        TextView textGoodsType;
        TextView textZengPin;
    }
}
